package com.sunny.design.observer.jdk;

import java.util.Observable;

/**
 * JDK提供的被观察者实现方式
 *
 * @author Sunny
 * @date 2020/1/15
 */
public class BaiDu extends Observable {

    private String name = "百度贴吧";

    private static BaiDu baidu = null;

    public static BaiDu getInstance() {
        if (baidu == null) {
            baidu = new BaiDu();
        }
        return baidu;
    }

    public String getName() {
        return name;
    }

    /**
     * 通知所有观察者
     *
     * @param question 问题
     */
    public void publishQuestion(Question question) {
        System.out.println(question.getUserName() + "在" + getName() + "上发布了一个问题！");
        setChanged();
        notifyObservers(question);
    }
}
